﻿using GeneralServices.PatternCommand;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleAppTestPatternCommand
{
    public class CommandCalc : AbstractCommand
    {
        public CommandCalc(IReceiver re, AbstractCommandArgs args) : base(re, args) {}

        public override void Execute()
        {
            Receiver.Action(this);
        }

        public override void UnExecute()
        {
            Receiver.Action(Undo());
        }

        public override AbstractCommand Undo()
        {
            CommandCalcArgs args = Arguments as CommandCalcArgs;
            CommandCalcArgs undoArgs = new CommandCalcArgs();


            switch (args.Operateur)
            {
                case '+':
                    undoArgs.Fill(new object[] { args.Operand, '-' });
                    break;
                case '-': undoArgs.Fill(new object[] { args.Operand, '+' });
                    break;
                case '*': undoArgs.Fill(new object[] { args.Operand, '/' });
                    break;
                case '/': undoArgs.Fill(new object[] { args.Operand, '*' });
                    break;
            }

            return new CommandCalc(Receiver, undoArgs);
        }
    }
}
